<?php 

/**
* 
*/
class AnswerController extends Controller
{
	private $db;
	public function __init()
	{
		$this->db=K('Answer');
	}
	//显示答案(要分页)
	public function index()
	{
		$data=$this->db->getList();
		$this->assign($data);
		$this->display();
	}

	//发布答案
	public function add()
	{
		if (IS_POST) {
			if ($this->db->addAnswer()) {
				$this->success('发布成功','index');
			}else{
				$this->error($this->db->error);
			}	
		}else{
			//获得所有问题
			$data=K('Question')->getList();
			$this->assign($data);
			$this->display();
		}
	}
	//修改答案
	public function edit()
	{
		if (IS_POST) {
			if ($this->db->editAnswer()) {
				$this->success('修改成功','index');
			}else{
				$this->error($this->db->error);
			}
		}else{
			$aid=Q('aid');
			$data=K('Answer')->where(" aid=$aid")->find();
			$this->assign('data',$data);
			$this->display();
		}
	}
	//删除答案
	public function del()
	{
		$aid=Q('aid');
		if ($this->db->delAnswer($aid)) {
			$this->success('删除成功','index');
		}else{
			$this->error($this->db->error);
		}
		
	}

}


 ?>